package cn.bdqn.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.bdqn.pojo.User;
//登录权限拦截器
public class SysInterceptor implements HandlerInterceptor {

	
	//进入请求前
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object obj) throws Exception {
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		//如果session有用户就放过去
		User userLogin = (User)request.getSession().getAttribute("userlogin");
		if(userLogin==null){
			response.sendRedirect(basePath+"login.html");
			return false;
		}else{
			return true;
		}
	}
	
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception e)
			throws Exception {
		System.out.println("拦截器完成后");

	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response,
			Object obj, ModelAndView mv) throws Exception {
		System.out.println("进入了拦截后");

	}

}
